# -*- coding: utf-8 -*-
# @File     : serializers.py
# @Author   : bingjia
# @Time     : 2020/7/27 16:41
# @Desc     : user序列化

from ..base.api import serializers

from . import models
from .services import get_user_photo_url


class UserSerializer(serializers.ModelSerializer):
    """
    用户序列化
    """
    full_name = serializers.SerializerMethodField()
    photo = serializers.SerializerMethodField()

    class Meta:
        model = models.User
        fields = ['id', 'username', 'full_name', 'email', 'bio', 'photo', 'lang', 'theme', 'is_active']

    def get_full_name(self, obj):
        return obj.get_full_name() if obj else ""

    def get_photo(self, user):
        return get_user_photo_url(user)


class UserAdminSerializer(serializers.ModelSerializer):
    """
    用户管理序列化
    """
    full_name = serializers.SerializerMethodField()
    photo = serializers.SerializerMethodField()

    class Meta:
        model = models.User
        fields = ['id', 'username', 'full_name', 'email', 'bio', 'photo', 'lang', 'theme', 'is_active']

    def get_full_name(self, obj):
        return obj.get_full_name() if obj else ""

    def get_photo(self, user):
        return get_user_photo_url(user)







